clear all
set seed 77007

** set working directory

use "study 3.dta"

*inferring device from resolution
gen device_os=0
replace device_os=1 if substr(metainfo_OperatingSystem, 1, 7)=="Android"
replace device_os=1 if substr(metainfo_OperatingSystem, 1, 6)=="iPhone"

*attention check
recode attncheck 1=1 *=0

*control variables
rename edu educ
gen male=sex
recode male 2/3=0
gen PID=pid
recode PID 1=2 2=6 3/4=4
recode PID 2=1 if dem==1
recode PID 6=7 if rep==1
recode PID 4=3 if ind==1
recode PID 4=5 if ind==2

*hostile sexism measures
recode is4 is9 (1=5) (2=4) (4=2) (5=1)
alpha is1-is5, item casewise asis gen(IS5)
replace IS5=(IS5-1)/4
egen IS5std=std(IS5)

recode ad1 ad2 ad3 ad4 ad5 ad6 ad7 ad8 (1=5) (2=4) (4=2) (5=1)
alpha ad1-ad5, item casewise asis gen(AD5)
replace AD5=(AD5-1)/4
egen AD5std=std(AD5)

*combined measure
egen HS5=rowfirst(IS5 AD5)
egen HS5std=rowfirst(AD5std IS5std)

*truncation of scale
recode IS5 0=1 1=1 .01/.99=0, gen(IS5_trunc)
recode AD5 0=1 1=1 .01/.99=0, gen(AD5_trunc)

*format indicator
gen revised=.
replace revised=0 if Format=="AD"
replace revised=1 if Format=="IS"

*metoo
recode metoo1 1=3 2=2 3=1 4=2
recode metoo4 2=0

irt hybrid (grm metoo1 metoo2 metoo3) (2pl metoo4)
predict Metoo_latent, latent

*FTs
gen FTwomen=(FT_1+FT_2+FT_4+FT_6+FT_9)/5
gen FTmen=(FT_3+FT_5+FT_7+FT_8+FT_10)/5
gen FTgendiff=FTmen-FTwomen

*control scale
recode control5-control8 (1=5) (2=4) (4=2) (5=1)
alpha control1-control4, item casewise asis gen(Control_R)
alpha control5-control8, item casewise asis gen(Control_F)
cor Control_R Control_F

*timers
gen time_AD5=time_ad1_PageSubmit
gen time_IS5=time_is1_PageSubmit


************
* analysis *
************

*reliability
alpha is1-is5, item casewise asis 
alpha ad1-ad5, item casewise asis 

*truncation
sum *trunc

*time
sum time_AD5 time_IS5, detail

*figure
hist IS5, xlab(0(.2)1) ylab(0(50)250) xtitle("Item-Specific Scale") freq saving(hist_is.gph, replace)
hist AD5, xlab(0(.2)1) ylab(0(50)250) xtitle("Agree-Disagree Scale") freq saving(hist_ad.gph, replace)
graph combine hist_ad.gph hist_is.gph, subtitle("")


*predictive - metoo
reg Metoo_latent c.HS5##i.revised PID ideo follow educ age male i.race device_os
est store metoo
margins revised, at(HS5=(0(.2)1))
marginsplot, ylab(-1(.5)1.5) recast(line) recastci(rarea) ciopt(color(gs10%20)) ytitle("Opposition to #MeToo") xtitle("Hostile Sexism") legend(label(1 "Agree-Disagree") label(2 "Item-Specific")) title("") subtitle("") saving(metoo5_s3.gph, replace)

*predictive - FTs
reg FTgendiff c.HS5##i.revised PID ideo follow educ age male i.race device_os
est store fts
margins revised, at(HS5=(0(.2)1))
marginsplot, ylab(-4(4)12) recast(line) recastci(rarea) ciopt(color(gs10%20)) ytitle("Men - Women") xtitle("Hostile Sexism") yline(0) 	legend(order(3 "Agree-Disagree" 4 "Item-Specific") rows(1)) title("") subtitle("") saving(FTG5_s3.gph, replace)

grc1leg metoo5_s3.gph FTG5_s3.gph, legendfrom(FTG5_s3.gph) subtitle("")

*discriminant validity
cor IS5 Control_R Control_F
cor AD5 Control_R Control_F
cor Control*

drop if Control_F==. | Control_R==.
drop if HS5==.

gen o5_1=.
gen o5_2=.
gen r5_1=.
gen r5_2=.

gen o11_1=.
gen o11_2=.
gen r11_1=.
gen r11_2=.

forval x=1/1000 {
preserve
bsample
qui cor AD5 Control_F
local o51=r(rho) in `x'
qui cor AD5 Control_R
local o52=r(rho) in `x'
qui cor IS5 Control_F
local r51=r(rho) in `x'
qui cor IS5 Control_R
local r52=r(rho) in `x'

restore
qui replace o5_1=`o51' in `x'
qui replace o5_2=`o52' in `x'
qui replace r5_1=`r51' in `x'
qui replace r5_2=`r52' in `x'

di `x'
}

sum o5* r5*
gen AD5_controldiff=o5_1-o5_2
gen IS5_controldiff=r5_1-r5_2
sum *controldiff
gen controldid5=.
replace controldid5=1 if AD5_controldiff>IS5_controldiff
replace controldid5=0 if AD5_controldiff<=IS5_controldiff
replace controldid5=. if (AD5_controldiff==. | IS5_controldiff==.)
tab controldid5


